//
//  MainViewController.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/23.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "MainViewController.h"
#import "MainBtnView.h"
#import "NewsFirstCell.h"
#import "MyWalletViewController.h"
#import "orderSubmitViewController.h"
#import "ChongZhiViewController.h"
#import "DZQViewController.h"
@interface MainViewController ()<SDCycleScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableV;
@property (nonatomic,strong)SDCycleScrollView *cycleScrollView;//轮播
@property (nonatomic,strong)NSMutableArray *lunBoArr;//轮播数组
@property (nonatomic,strong)MainBtnView *mianBtnView;//主按钮View
@property (nonatomic,strong)NSArray *btnImageArr;//主按钮图片数组
@property (nonatomic,assign)BOOL isShowActImageV;//是否展示活动横幅
@property (nonatomic,strong)UIImageView *hengFuImageV;//横幅图片
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTitleWithTitle:@"安安洗车"];
    _isShowActImageV = YES;
    [self.view addSubview:self.tableV];
}
-(NSArray *)btnImageArr//初始化图片数组Arr
{
    if (!_btnImageArr) {
        _btnImageArr = @[@"woyaoxiche",@"mybook",@"qianbao",@"chongzhi",@"dianzijuan",];
    }
    return _btnImageArr;
}
-(UITableView *)tableV//创建tableView
{
    if (!_tableV) {//_table不存在
        _tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREENW, SCREENH-64-49) style:UITableViewStyleGrouped];
        _tableV.rowHeight = 60*screenW_6;
        _tableV.backgroundColor = backColor;
        _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableV.showsVerticalScrollIndicator = NO;
        _tableV.delegate = self;
        _tableV.dataSource = self;
        //注册Cell
//        [_tableV registerClass:[AroundCell class] forCellReuseIdentifier:AroundCellID];
//        //刷新
//        _tableV.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
//            _PageNumber = 1;
//            [self getListData:YES];
//            [self addLunBoRequest:_cityName];;
//        }];
//        //加载
//        _tableV.mj_footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
//            _PageNumber++;
//            [self getListData:NO];
//        }];
    }
    return _tableV;
}
//轮播
-(SDCycleScrollView *)cycleScrollView
{
    NSArray *imageArr = [[NSArray alloc]initWithObjects:@"http://scimg.jb51.net/allimg/150629/14-1506291A242927.jpg",@"http://pic1.16pic.com/00/13/02/16pic_1302498_b.jpg",nil];
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0,0,SCREENW,165*screenW_6) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycleScrollView.currentPageDotColor = [UIColor whiteColor];
        _cycleScrollView.autoScrollTimeInterval = 4.0f;
        _cycleScrollView.userInteractionEnabled = YES;
        _cycleScrollView.delegate = self;
    }
    _cycleScrollView.imageURLStringsGroup = imageArr;//加载的图片数组
    return _cycleScrollView;
}
//主按钮View
-(MainBtnView *)mianBtnView
{
    if (!_mianBtnView) {
        _mianBtnView = [[MainBtnView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 300*screenW_6) BtnImageArr:self.btnImageArr];
        __weak typeof(self)weakSelf = self;
        _mianBtnView.btnSelectBlock = ^(NSInteger tagNumber){
            
            if (tagNumber == 0) {//我要洗车
                [weakSelf.navigationController pushViewController:[orderSubmitViewController new] animated:YES];
            }else if (tagNumber == 1)//我的订单
            {
                 weakSelf.tabBarController.selectedIndex = 1;
            }
            else if (tagNumber == 2)//我的钱包
            {
                [weakSelf.navigationController pushViewController:[MyWalletViewController new] animated:YES];
            }
            else if (tagNumber == 3)//充值中心
            {
                [weakSelf.navigationController pushViewController:[ChongZhiViewController new] animated:YES];
            }
            else if (tagNumber == 4)//我的电子券
            {
                [weakSelf.navigationController pushViewController:[DZQViewController new] animated:YES];
            }
            
        };
    }
    return _mianBtnView;
}
//横幅
-(UIImageView *)hengFuImageV
{
    if (!_hengFuImageV) {
        _hengFuImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 85*screenW_6)];
        _hengFuImageV.image = [UIImage imageNamed:@"guanggao"];
    }
    return _hengFuImageV;
}
#pragma TableViewDegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    return 0;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (_isShowActImageV) {//是否现实横幅
        return 3;
    }
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5*screenW_6;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {//轮播
        return 165*screenW_6;
    }else if (section == 1)//主按钮
    {
        return 295*screenW_6;
    }else{//横幅
        return 85*screenW_6;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //jiza
    NewsFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[NewsFirstCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    [cell loadCell:@"没有关系我们只是朋友" SecondStr:@"偶尔会替你分担你的伤口"];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {//轮播
        return self.cycleScrollView;
    }else if (section == 1)//主按钮
    {
        return self.mianBtnView;
    }else{//横幅
        return self.hengFuImageV;
    }
}
@end
